package com.youzheng.serviceImpl;

import com.youzheng.entity.Product;
import com.youzheng.mapper.ProductMapper;
import com.youzheng.service.IProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class ProductServiceImpl implements IProductService {
    @Resource
    private ProductMapper mapper;

    @Override
    public PageInfo<Product> findAllProducts(Integer pageNum, Integer pageSize, String pname) {
        PageHelper.startPage(pageNum, pageSize);
        List<Product> products = mapper.findAllProducts(pname);
        PageInfo<Product> pageInfo = new PageInfo<>(products);
        return pageInfo;
    }

    @Override
    public Product findProductByPid(Integer pid) {
        return mapper.findByPid(pid);
    }

    @Override
    public void updateProduct(Product product) {
        mapper.updateProduct(product);
    }

    @Override
    public void deleteProduct(Integer id) {
        mapper.deleteProduct(id);
    }
}


